﻿using System.Web.Mvc;
using System.Web.Security;
using GiaoXuLanTranh_MucVu.Models;
using InfoTech.Core.Data.SqlClient;
using InfoTech.LanTranh.MucVu.Bussiness;
using InfoTech.Mvc.LanTranh.MucVu.Models;

namespace GiaoXuLanTranh_MucVu.Controllers
{
    public class AccountController : Controller
    {
        //
        // GET: /Account/

        public ActionResult LogOn()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogOn(FormCollection formCollection)
        {
            string username = formCollection["Username"];
            string password = formCollection["Password"];
            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                USER user = new USER();
                user.USERNAME = username;
                user.PASSWORD = Encrypt.Encrypte(password);
                user.Select();
                if (user.IsPersistence)
                {
                    if (Membership.ValidateUser("admin", "admin1@"))
                    {
                        Session["User"] = new USERModel(user);
                        FormsAuthentication.SetAuthCookie("admin", false);
                        return Redirect(Request.QueryString["ReturnUrl"]);
                    }
                }
            }

            return View();
        }

    }
}
